package cn.sinothk.map.amap.demo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import cn.sinothk.map.amap.base.MapCallback
import cn.sinothk.map.amap.location.AMapLocate
import cn.sinothk.map.amap.location.AMapLocationEntity
import kotlinx.android.synthetic.main.map_demo_activity_main.*

class LocationDemoMainActivity : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.location_demo)

        locationBtn.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v) {

            locationBtn -> {
                AMapLocate().locationOnce(this, object : MapCallback<AMapLocationEntity> {
                    override fun onFail(msg: String?) {
                    }

                    override fun onSuccess(mapInfo: AMapLocationEntity) {
                        Toast.makeText(
                            this@LocationDemoMainActivity,
                            mapInfo.address,
                            Toast.LENGTH_SHORT
                        ).show()
                    }
                })
            }
        }
    }
}